const { Page, wx } = require('./VirtualWx')
const { initLog } = require('./log')

const { sop } = require('./so')
const { xState } = require('./state')
const [x, setX] = xState

initLog()

Page(sop({
    name: 'index',
    data: {
        a: 1,
        c: 10,
    },
    onLoad: function() {
        console.log(x())
        setX(1)
        this.request({
            url: '/path/to/api',
            delay: 1500,
            success: function(data) {
                console.log(data)
                for (let i=0;i<10;i++) {
                    for (let j=0;j<10;j++) {
                        this.setData({
                            e: i+j,
                        })
                    }
                }
            }
        })
    },
    onReady: function() {
        console.log('before', this.data)
        this.setData({
            a: 2,
            b: 3,
        })
        console.log(x())
        setX(10)
        console.log('after', this.data)
        for (let i=0;i<10;i++) {
            this.setData({
                a: i,
            })
        }
    },
    doAction: function(e) {
        console.log(e, x())
        setX(100)
        for (let i=0;i<10;i++) {
            for (let j=0;j<10;j++) {
                this.setData({
                    d: i*j,
                })
            }
        }
        wx.gotoPage('log')
    }
}))

wx.gotoPage('index')
